<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('kh_form')" />
</head>
<body class="white-bg">
	<div class="main-content">
		<form class="form-horizontal" id="form">
			<input id="pageFlag" name="pageFlag" type="hidden" th:value="${scene.pageFlag}" />
			<input id="id" name="id" type="hidden" th:value="${scene.id}" />
			<input id="attachChangeFlag" name="attachChangeFlag" type="hidden" />
			<input id="reserveStatus" name="reserveStatus" type="hidden" th:value="${scene.reserveStatus}" />
			<input id="personNameFlag" name="personNameFlag" type="hidden" th:value="${scene.personNameFlag}" />
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">考核日期</label>
				<div class="col-sm-8">
					<input name="dayId" id="dayId" th:value="${scene.dayId}" class="form-control" type="text" required />
				</div>
			</div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">被考核部门</label>
                <div class="col-sm-8">
                    <select id="dept.deptId" name="dept.deptId" class="form-control m-b" required>
                        <option value="">请选择</option>
                        <option th:each="dept : ${deptList}" th:text="${dept.deptName}" th:value="${dept.deptId}"
                            th:selected="${scene.dept.deptId == dept.deptId}" />
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">得分<br/>(请填写非0的数字)</label>
                <div class="col-sm-8">
                    <input name="score" id="score" th:value="${scene.score}" class="form-control" type="text" required />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">考核内容</label>
                <div class="col-sm-8">
                    <textarea class="form-control" name="content1" id="content1"
                        th:text="${scene.content1}" rows="3" maxlength="512" required></textarea>
                </div>
            </div>
            <!-- 
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">考核依据</label>
                <div class="col-sm-8">
                    <textarea class="form-control" name="content2" id="content2"
                        th:text="${scene.content2}" rows="3" maxlength="512" required></textarea>
                </div>
            </div>
             -->
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">考核形式</label>
                <div class="col-sm-8">
                    <textarea class="form-control" name="content3" id="content3"
                        th:text="${scene.content3}" rows="3" maxlength="512" required></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">图片</label>
                <div class="col-sm-8">
                    <table id="pic_region">
                    </table>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label"></label>
                <div class="col-sm-8">
                    <a href="javascript:uploadPic()" id="uploadPicBtn" class="btn btn-warning btn-sm fa fa-plus">上传附件</a>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">值班领导</label>
                <div class="col-sm-8">
                    <select class="form-control" name="fgldChecker.userId" id="fgldChecker.userId" th:with="fgldList=${fgldList}">
						<option value="">--请选择--</option>
						<option th:each="item : ${fgldList}" th:text="${item.userName}" th:value="${item.userId}"
							th:selected="${scene.fgldChecker.userId == item.userId}"></option>
					</select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">
                	<span th:if="${'1' == scene.personNameFlag}">当日值班主任</span>
                	<span th:if="${'2' == scene.personNameFlag}">特警队员一</span>
                </label>
                <div class="col-sm-2">
                    <input name="person1" id="person1" th:value="${scene.person1}" class="form-control" type="text" required />
                </div>
                <label class="col-sm-2 control-label is-required">
                	<span th:if="${'1' == scene.personNameFlag}">应急分队人员</span>
                	<span th:if="${'2' == scene.personNameFlag}">特警队员二</span>
                </label>
                <div class="col-sm-2">
                    <input name="person2" id="person2" th:value="${scene.person2}" class="form-control" type="text" required />
                </div>
            </div>
			
			<div style="clear:both;"></div>
			<h4 class="form-header h4" th:if="${'1' == showCheckResult}" style="margin-top:20px;">审批信息</h4>
			<div class="row" th:if="${'1' == showCheckResult}">
				<div class="col-sm-6">
					<label class="col-sm-4 control-label is-required">审批结果</label>
					<div class="col-sm-6">
						<label class="radio-box"> <input type="radio" name="checkResult" value="APPROVED" /> 通过 </label>
						<label class="radio-box"> <input type="radio" name="checkResult" value="REJECTED" /> 拒绝 </label>
					</div>
				</div>
				<div class="col-sm-6">
					<label class="col-sm-4 control-label">审批意见</label>
					<div class="col-sm-6">
						<input class="form-control" type="text" name="checkDesc" id="checkDesc" />
					</div>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: datetimepicker-css" />
	<th:block th:include="include :: datetimepicker-js" />
	<script th:inline="javascript">
		var prefix = ctx + "rate/scene";
		var pageFlag = [[${scene.pageFlag}]];
		
		$(function() {
			$("#dayId").datetimepicker({
				format: 'yyyy-mm-dd',
				autoclose: true,
				startView: 2,
				minView: 2
			});
			
			$("#uploadPicBtn").hide();
			if ("ADD" == pageFlag || "EDIT" == pageFlag) {
				$("#uploadPicBtn").show();
			} else if ("VIEW" == pageFlag) {
				$("#form input[type='text']").prop("disabled", true);
				$("#form textarea").prop("disabled", true);
				$("#form select").prop("disabled", true);
			} else if ("CHECK1" == pageFlag) {
				$("#score").prop("disabled", true);
			}
			
			var pics = 
			[
				[# th:each="a : ${scene.attachList}"]
					{
						id: [[${a.id}]],
						filename: [[${a.filename}]],
						type: [[${a.type}]]
					},
				[/]
			];
			$.each(pics, function(i, p) {
				addPic(p, true);
			});
			
			if ("ADD" != pageFlag && "EDIT" != pageFlag) {
				$("#pic_region .delete_img").hide();
			}
		});
		
		function submitHandler() {
			if (pageFlag == "ADD" || pageFlag == "EDIT") {
				if ($.validate.form()) {
					$.modal.confirm("确定保存数据？", function() {
						$.operate.save(prefix + "/save", $('#form').serialize());
					});
				}
			} else if (pageFlag == "CHECK10" || pageFlag == "CHECK20") {
				var checkedResult = $("input[name='checkResult']:checked").val();
				if (checkedResult == null) {
					$.modal.alertWarning("请选择审批结果！");
					return false;
				}
				/*
				if ($("input[name='checkDesc']").val() == "") {
					$.modal.alertWarning("请填写审批意见！");
					return false;
				}
				**/
				
				//if ($.validate.form()) {
					$.operate.save(prefix + "/submitCheck", $('#form').serialize());
				//}
			} else {
				var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
				parent.layer.close(index); //再执行关闭
				return true;
			}
		}
		
		function delPic(id) {
			$.modal.confirm("<font color='red'>确定要删除该图片吗？</font>", function() {
    			$("#img_tr_" + id).remove();
    			$("#attachChangeFlag").val("1");
			});
		}
		function addPic(attach, init) {
			var type = attach.type;
			var id = attach.id;
			var filename = attach.filename;
			if (!id || !filename) {
				$.modal.alertError("图片ID或NAME为空！");
				return;
			}
			var region = $("#pic_region");
			if (region != null) {
				var ele = $('<tr id="img_tr_'+id+'">' +
								'<td class="" style="">' +
									'<input type="hidden" name="attachIds" value="'+id+'" />' +
									'<a href="javascrpit:void(0);" onclick="viewPic(\''+id+'\')">'+filename+'</a>' +
								'</td>' +
								'<td>' +
									'<img style="cursor:pointer;margin-left:50px;" class="delete_img" src="'+ctx+'img/deletered.png" width="17x" onclick="delPic(\''+id+'\')"></img>' +
								'</td>' +
							'</tr>');
				region.append(ele);
			} else {
				alert("region is null");
			}
			
			if (!init) {
				$("#attachChangeFlag").val("1");
			}
			// $.modal.alertSuccess("图片上传成功！");
		}
		
		function viewPic(id) {
			window.open(ctx + "rate/attach/viewImg?id="+id);
			/**
			var img = "<img src='" + ctx + "rate/attach/viewImg?id="+id+"' />";
			layer.open({  
			    type: 1,  
			    shade: false,  
			    title: false, //不显示标题  
			    fix: false,
			    maxmin: true,
			    area:['auto','auto'],  
			    content: img, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响  
			    cancel: function () {  
			        //layer.msg('图片查看结束！', { time: 5000, icon: 6 });  
			    }  
			});
			**/
		}
		
		function uploadPic() {
			var currentId = "uploadFileForm";
			layer.open({
        		type: 1,
        		area: ['400px', '230px'],
        		fix: false,
        		//不固定
        		maxmin: true,
        		shade: 0.3,
        		title: '上传图片',
        		content: $('#' + currentId).html(),
        		btn: ['<i class="fa fa-check"></i> 上传', '<i class="fa fa-remove"></i> 取消'],
        		// 弹层外区域关闭
        		shadeClose: true,
        		btn1: function(index, layero){
        			var file = layero.find('#file').val();
        			if (file == ''){
        				$.modal.msgWarning("请选择文件。");
        				return false;
        			}
        			if (!$.common.endWith(file, '.jpg')
           							&& !$.common.endWith(file, '.JPG')
           							&& !$.common.endWith(file, '.jpeg')
           							&& !$.common.endWith(file, '.JPEG')){
           				$.modal.msgWarning("仅支持图片格式文件上传！");
           				return false;
           			}
        			var index = layer.load(2);
        			$.modal.disable();
        			var formData = new FormData();
        			formData.append("file", $('#file')[0].files[0]);
        			$.ajax({
        				url: ctx + "rate/attach/upload?type=scene",
        				data: formData,
        				cache: false,
        				contentType: false,
        				processData: false,
        				type: 'POST',
        				success: function (result) {
        					if (result.code == web_status.SUCCESS) {
        						$.modal.closeAll();
        						addPic(result.data, false);
        						$.modal.enable();
        					} else {
        						layer.close(index);
        						$.modal.enable();
        						$.modal.alertError(result.msg);
        					}
        				}
        			});
        		}
        	});
		}
	</script>
</body>
<script id="uploadFileForm" type="text/template">
<form enctype="multipart/form-data" class="mt20 mb10">
	<div class="col-xs-offset-1">
		<input type="file" id="file" name="file"/>
		<div class="mt10 pt5">
		</div>
		<font color="red" class="pull-left mt10">
			提示：仅支持jpg、jpeg、png等图片格式！
		</font>
	</div>
</form>
</script>
</html>